package com.xja.gittest.service.impl;

import com.xja.gittest.entity.Score;
import com.xja.gittest.entity.Student;
import com.xja.gittest.mapper.ScoreMapper;
import com.xja.gittest.mapper.StudentMapper;
import com.xja.gittest.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ScoreServiceImpl implements ScoreService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ScoreMapper scoreMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addScoreByStuId(Integer stuId, Score score) {
        Student student=studentMapper.selectByPrimaryKey(stuId);
        if(student!=null){
            score.setStuId(stuId);
            scoreMapper.insertSelective(score);
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateScoreById(Integer id, Score score) {
        score.setsId(id);
        scoreMapper.updateByPrimaryKeySelective(score);
    }
}
